<?php


namespace App\Listeners;


use App\Events\OrderPaySuccess;
use App\Services\OfficialTemplateService;

class OrderPaySuccessNoticeListener
{
    public $order;
    public $payType;
    public $attach;

    /**
     * Handle the event.
     *
     * @param  OrderPaySuccess $event
     * @return void
     */
    public function handle(OrderPaySuccess $event)
    {
        $this->order = $event->order;
        $this->attach = $event->attach;
        $this->payType = $event->payType;

        switch ($this->attach) {
            case 'legwork':
                //购买商品
                $this->doLegwork();
                break;
            case 'recharge_balance':
                $this->doRechargeBalance();
                break;
        }
    }

    private function doLegwork()
    {
        info('通知配送单支付成功');
        OfficialTemplateService::sendNewOrder($this->order);
    }

    private function doRechargeBalance()
    {
        info('通知充值成功');
        OfficialTemplateService::rechargeBalanceSuccess($this->order);
    }
}